<template>
  <teleport to="#header">
    <van-nav-bar title="Home" :fixed="true" safe-area-inset-top />
  </teleport>

  <h1>折线图</h1>

  <div ref="elChart" style="width: 100%; height: 340px"></div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted } from "vue"
import * as echarts from "echarts/lib/echarts"

// // 最新的引入方式
import { LineChart } from "echarts/charts"

// // echarts组件使用到的需要引入
import "echarts/lib/component/legend"
import "echarts/lib/component/title"
import "echarts/lib/component/tooltip"
import "echarts/lib/component/grid"

echarts.use([LineChart])

function loadChart(elChart: unknown) {
  // 基于准备好的dom，初始化echarts实例
  const myChart = echarts.init(elChart)
  // 指定图表的配置项和数据
  const option = {
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value'
    },
    series: [{
        data: [150, 230, 224, 218, 135, 147, 260],
        type: 'line'
    }]
  }
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option)
}
export default defineComponent({
  name: "Home",
  setup() {
    const elChart = ref()
    onMounted(() => {
      loadChart(elChart.value)
    })
    return {
      elChart,
    }
  },
})
</script>
<style lang="less">
h1 {
  margin: 20px;
  color: @color-primary;
}
</style>
